package com.example.mycomposelearing

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.mycomposelearing.custom.CustomImageMainActivity
import com.example.mycomposelearing.custom.CustomMainActivity
import com.example.mycomposelearing.dataobserval.ObserveDataActivity
import com.example.mycomposelearing.gesture.MainGestureActivity
import com.example.mycomposelearing.scroll.ScrollMainActivity
import com.example.mycomposelearing.ui.theme.MyComposeLearingTheme

class MainActivity : ComponentActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyComposeLearingTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                ) {
                    Greeting("Android")
                }
            }
        }
    }


    @Composable
    fun Greeting(name: String) {
        val scrollState = rememberScrollState()
        Column(
            modifier = Modifier
                .fillMaxSize()
                .verticalScroll(scrollState)
        ) {
            Button(
                onClick = {
                    toast("Button的点击事件")
                    startActivity(Intent(this@MainActivity, BaseLayoutMainActivity::class.java))
                },
                modifier = Modifier.fillMaxWidth()
                    .align(Alignment.CenterHorizontally),
                content = {
                    Box() {
                        Text(
                            text = "跳转到基础位置布局的界面 BaseLayoutMainActivity",
                            modifier = Modifier.wrapContentWidth().background(Color(0xFCF51D82)),
                            style = TextStyle(fontSize = 20.sp),
                            textAlign = TextAlign.Center
                        )
                    }
                }
            )
            Text(
                text = "跳转到基础位置布局的界面 BaseLayoutMainActivity",
                modifier = Modifier.wrapContentWidth().background(Color(0xFCF51D82)),
                style = TextStyle(fontSize = 20.sp),
                textAlign = TextAlign.Center
            )
            Column(
                modifier = Modifier.wrapContentHeight(),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Surface(
                    shape = RoundedCornerShape(6.dp),

                    color = Color(0xffFF0000)
                ) {
                    Text(
                        text = "跳转到自定义的view CustomMainActivity",
                        modifier = Modifier
                            .height(60.dp)
                            .align(Alignment.Start)
                            .clickable {
                                startActivity(
                                    Intent(
                                        this@MainActivity,
                                        CustomMainActivity::class.java
                                    )
                                )
                            },
                        textAlign = TextAlign.Center,

                        )
                }

                Image(
                    painter = painterResource(R.drawable.ic_launcher_background),
                    contentDescription = null,
                    modifier = Modifier.align(Alignment.End)
                )
            }

            Button(
                onClick = {
                    toast("Button的点击事件")
                    startActivity(Intent(this@MainActivity, ObserveDataActivity::class.java))
                },
                modifier = Modifier
                    .padding(vertical = 6.dp)
                    .background(Color.Blue)
                    .padding(6.dp)
                    .fillMaxWidth()
                    .clickable {
                        toast("Modifier的点击事件")
                    },
                content = {
                    Text(text = "跳转到ObserveDataActivity观察数据更新")
                })
            Button(
                onClick = {
                    startActivity(Intent(this@MainActivity, ScrollMainActivity::class.java))
                },
                modifier = Modifier
                    .padding(vertical = 6.dp)
                    .background(Color.Blue)
                    .padding(6.dp),
                content = {
                    Text(text = "跳转到ScrollMainActivity嵌套滑动")
                })

            Button(
                onClick = {
                    startActivity(Intent(this@MainActivity, CustomImageMainActivity::class.java))
                },
                modifier = Modifier
                    .padding(vertical = 6.dp)
                    .background(Color.Blue)
                    .padding(6.dp),
                content = {
                    Text(text = "跳转到 CustomImageMainActivity 图片相关")
                })


            Button(
                onClick = {
                    startActivity(Intent(this@MainActivity, MainGestureActivity::class.java))
                },
                modifier = Modifier
                    .padding(vertical = 6.dp)
                    .background(Color.Blue)
                    .padding(6.dp),
                content = {
                    Text(text = "跳转到 MainGestureActivity 手势相关")
                })


        }
    }


    @Composable
    private fun PhotographerCard2() {
        //帮我写一个左边是图片右边是两个text文本，文本垂直对齐左边的图片


    }


    private fun toast(content: String?) {
        Toast.makeText(this@MainActivity, content, Toast.LENGTH_SHORT).show()
    }

    /**
     *预览
     */
    @Preview(showBackground = true)
    @Composable
    fun DefaultPreview() {
        MyComposeLearingTheme {
            Greeting("Android")
        }
    }
}


